﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using T_Material.API.Application.Commands.PurchaseCommand;
using T_Material.API.Application.Commands.RequisitionCommand;
using T_Material.Domain;

namespace T_Material.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName =nameof(ApiversionInfo.物资采购))]
    public class PurchaseAPIController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly Logger<PurchaseAPIController> logger;

        public PurchaseAPIController(IMediator mediator, Logger<PurchaseAPIController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        [HttpGet]
        public IActionResult text1()
        {
            try
            {
                Purchase info = null;
                info.GoodsName = "康建东";
                return Ok();
            }
            catch (Exception)
            {
                logger.LogError("康建东执行任务发生了错误！！！");
                throw;
            }
        }
        
        /// <summary>
        /// 添加物资采购
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> PurchaseAdd(PurchaseCreatedCommand command)
        {
                return await mediator.Send(command);          
        }

        /// <summary>
        /// 删除物资采购
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> PurchaseDelete([FromQuery] PurchaseDeleteCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 修改物资采购
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> PurchaseUpdate(PurchaseUpdateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 添加物资采购提交审批
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> PurchaseAddState(PurchaseCreatedStateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 添加物资采购提交审批
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> PurchaseAddStateShenPi(PurchaseUpdateShenPiState command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 添加物资采购提交审批
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> PurchaseUpdadeState(PurchaseUpdateState command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 批删物资采购
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> PurchaseDels([FromQuery]PurchaseDelsCommand command)
        {
            try
            {
                return await mediator.Send(command);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
